package com.study.classLoader;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class ClassLoaderTest {

    /*public static void main(String[] args) {

//		System.out.println(System.getProperty("sun.boot.class.path"));
//		System.out.println(System.getProperty("java.ext.dirs"));
//		System.out.println(System.getProperty("java.class.path"));


        ClassLoader cl = ClassLoaderTest.class.getClassLoader();

        System.out.println("ClassLoader is:" + cl.toString());
        System.out.println("ClassLoader P is:" + cl.getParent().toString());
        System.out.println("ClassLoader PP is:" + cl.getParent().getParent().toString());
//        System.out.println("ClassLoader PPP is:" + cl.getParent().getParent().getParent().toString());

    }*/


    public static void main(String[] args) {

        //创建自定义classloader对象。
        DiskClassLoader diskLoader = new DiskClassLoader("D:\\");
        try {
            //加载class文件
            Class c = diskLoader.loadClass("com.study.classLoader.Test");

            if(c != null){
                try {
                    Object obj = c.newInstance();
                    Method method = c.getDeclaredMethod("say",null);
                    //通过反射调用Test类的say方法
                    method.invoke(obj, null);
                } catch (InstantiationException | IllegalAccessException
                        | NoSuchMethodException
                        | SecurityException |
                        IllegalArgumentException |
                        InvocationTargetException e) {
                    e.printStackTrace();
                }
            }
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }

    }

}
